'''
  @Description      
  @auther         leizi
  @create          2020-02-09 15:04
'''
# /usr/local/bin
from config.useconfig import *
import os, threading
from until.commonadb import pull_file
from until.filetools import write_file
from until.GetFPS import GetFPs
from until.getphone import *
from until.log import LOG, logger


@logger("开始monkery测试")
def monkey(testapkname, time):
    cmd = '/Users/lileilei/Downloads/android-sdk-macosx/platform-tools/adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p ' + testapkname + ' --uiautomatortroy --running-minutes ' + time + ' -v -v --throttle 500 --output-directory /sdcard/max1/ >report.txt'
    os.system(cmd)


@logger("获取cpu")
def get(device, packname, path, performancepath):
    while True:
        Fps = GetFPs(device, packname).getfps()
        cpu = caijicpu(packname)
        leak = getnencun(packname)
        conet = str(Fps) + "_" + str(cpu) + "_" + str(leak)
        write_file(performancepath, conet)
        pull_file(device, "/sdcard/max1/", path)


def runcmd(time, device, path, performancepath, packname):
    LOG.info("启动测试")
    for i in range(2):
        t1 = threading.Thread(target=monkey, args=(packname, time))
        t2 = threading.Thread(target=get, args=(device, packname, path, performancepath))
        t1.start()
        t2.start()
